/*
 * 
 */
package com.china08.yxyapi.entity.mg.moments;

import java.time.LocalDateTime;
import java.util.Date;

import javax.persistence.Id;

import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import com.china08.yxyapi.entity.mg.MongoBaseEntityNoId;
import com.china08.yxyapi.util.DateAndLocalDateConvertUtils;
import com.china08.yxyapi.util.DateToolUtils;

/**
 * 班级圈评论,每一个班级圈的每一个评论存储一条记录
 * 
 * @author Richard.Wang
 */
@SuppressWarnings("serial")
@Document(collection = "yxy.tea.moments.comment")
public class YxyMomentsComment extends MongoBaseEntityNoId {

    /** The id. */
    @Id
    private String id;

    /** The moments id. */
    @Indexed
    @Field(value = "moments_id")
    private String momentsId;// 对应的班级圈id

    /** The user id. */
    @Field(value = "user_id")
    private String userId;// 评论用户id

    /** The user nick. */
    @Field(value = "user_nick")
    private String userNick;// 评论用户名称

    /** The avatar. */
    @Field(value = "avatar")
    private String avatar;// 评论人头像

    /** 被回复人Id */
    @Field(value = "replyer_id")
    private String replyerId;// 评论显示的title

    /**
     * 被回复人名称
     */
    @Field(value = "replyer_nick")
    private String replyerNick;

    /** The comment. */
    @Field(value = "comment")
    private String comment;// 评论内容

    /**
     * Gets the id.
     *
     * @return the id
     */
    public String getId() {
        return id;
    }

    /**
     * Sets the id.
     *
     * @param id
     *            the id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * Gets the moments id.
     *
     * @return the moments id
     */
    public String getMomentsId() {
        return momentsId;
    }

    /**
     * Sets the moments id.
     *
     * @param momentsId
     *            the moments id
     */
    public void setMomentsId(String momentsId) {
        this.momentsId = momentsId;
    }

    /**
     * Gets the user id.
     *
     * @return the user id
     */
    public String getUserId() {
        return userId;
    }

    /**
     * Sets the user id.
     *
     * @param userId
     *            the user id
     */
    public void setUserId(String userId) {
        this.userId = userId;
    }

    /**
     * Gets the user nick.
     *
     * @return the user nick
     */
    public String getUserNick() {
        return userNick;
    }

    /**
     * Sets the user nick.
     *
     * @param userNick
     *            the user nick
     */
    public void setUserNick(String userNick) {
        this.userNick = userNick;
    }

    /**
     * Gets the avatar.
     *
     * @return the avatar
     */
    public String getAvatar() {
        return avatar;
    }

    /**
     * Sets the avatar.
     *
     * @param avatar
     *            the avatar
     */
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    /**
     * Gets the comment.
     *
     * @return the comment
     */
    public String getComment() {
        return comment;
    }

    /**
     * Sets the comment.
     *
     * @param comment
     *            the comment
     */
    public void setComment(String comment) {
        this.comment = comment;
    }

    /**
     * 评论距离现在多久以前 <br>
     * </br>
     * <p>
     * 发布24小时内，显示“发布于XX小时XX分钟前”，
     * </p>
     * <p>
     * 超过24小时，显示“发布于日期+时间”，日期+时间显示样式“16-12-12 23：59”，
     * </p>
     * 
     * @return
     */
    public String getBefPre() {
        Date date = this.getCreatedDate();
        if (date == null) { //
            return "";
        }
        // 当前时间
        LocalDateTime currentlocalDateTime = LocalDateTime.now();
        Date currentDate = DateAndLocalDateConvertUtils.asDate(currentlocalDateTime);
        currentlocalDateTime = currentlocalDateTime.minusHours(24);
        // 发布时间
        LocalDateTime dateLocalDateTime = DateAndLocalDateConvertUtils.asLocalDateTime(date);
        if (currentlocalDateTime.isAfter(dateLocalDateTime)) {// 超过了24小时
            // 发布于日期+时间
            return DateToolUtils.format(date, DateToolUtils.FORMAT_SHORT_YMD);
        } else {// 在24小时范围内
            Long dateCount = currentDate.getTime() - date.getTime();
            int hours = (int) (dateCount / 1000 / 60 / 60);
            int minis = (int) (dateCount / 1000 / 60 % 60);
            int ms = (int) (dateCount / 1000 % 60);
            if (hours != 0) { //
                if (minis == 0) {//
                    return hours + "小时前";
                }
                if (minis == 60) { //
                    return hours + "小时 59分钟前";
                }
                return hours + "小时" + minis + "分钟前";
            } else {
                if (minis != 0) {
                    if (ms == 0) {//
                        return minis + "分钟前";
                    }
                    if (ms == 60) { //
                        return minis + "分钟前";
                    }
                    return minis + "分钟前";
                } else {
                    if (ms == 0) {//
                        return minis + "1秒前";
                    }
                    if (ms == 60) { //
                        return "1分钟前";
                    }
                    return ms + "秒前";
                }
            }
        }
    }

    public String getReplyerId() {
        return replyerId;
    }

    public void setReplyerId(String replyerId) {
        this.replyerId = replyerId;
    }

    public String getReplyerNick() {
        return replyerNick;
    }

    public void setReplyerNick(String replyerNick) {
        this.replyerNick = replyerNick;
    }

}
